package us.icitap.cm.ui.policecase;



public class CaseLayout {

//	final CaseTree caseTree = new CaseTree();
//	final EventReportDataLayout erDataLayout = new EventReportDataLayout();
//	final PersonDataLayout personDataLayout = new PersonDataLayout();
//	final CaseDataLayout caseDataLayout = new CaseDataLayout();
//	final PlaceDataLayout placeDataLayout = new PlaceDataLayout();
//	final VehicleDataLayout vehicleDataLayout = new VehicleDataLayout();
//	final ItemDataLayout itemDataLayout = new ItemDataLayout();
////	final NumberDataLayout numberDataLayout = new NumberDataLayout();
//	final WeaponDataLayout weaponDataLayout = new WeaponDataLayout();
//	final DrugDataLayout drugDataLayout = new DrugDataLayout();
//	final OrganizationDataLayout organizationDataLayout = new OrganizationDataLayout();
//	final OfficerDataLayout officerDataLayout = new OfficerDataLayout();
//	final EntityEntityAssocDataLayout assocDataLayout = new EntityEntityAssocDataLayout();
//	final DocumentDataLayout docDataLayout = new DocumentDataLayout();
//	
//	final HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
//	
//	private Case pCase;
//	
//	private AppEntity reportEntity;
//	
//	private AppEntity srEntity;
//	
//	
//	Map<EntityTypeEnum , AppEntityLayout> map = new HashMap<EntityTypeEnum, AppEntityLayout>();
//	
//	public CaseLayout() {
//		this.addComponent(splitPanel);
//		
//		VerticalLayout vl = new VerticalLayout();
//		vl.addComponent(caseTree);
//		CustButton cb = new CustButton("Ruaj");
//		cb.setSizeFull();
//		vl.addComponent(cb);
//		cb.addClickListener(new ClickListener() {
//			
//			@Override
//			public void buttonClick(ClickEvent event) {
//				if(CaseManagementUI.getActualAction().equals(ActionEnum.NEW_ER) 
//						&& !pCase.hasEventReport()){
//					HandleNotification.showWarningOnScreen("Ceshtja duhet te permbaje te pakten nje raport ngjarje");
//					return;
//				}
//				else if(CaseManagementUI.getActualAction().equals(ActionEnum.NEW_SR) 
//						&& !pCase.hasSupplementReport()){
//					HandleNotification.showWarningOnScreen("Ceshtja duhet te permbaje te pakten nje raport suplementar");
//					return;
//				}
//					
//					
//					
//				if(pCase.getAssociationsList() != null)
//					for (EntityAssociations ea : pCase.getAssociationsList()) {
//						ea.setId(null);
//					}
//				
//				CustConfirmDialog.show(getConfirmDialogAction(), getUI(), "<b>Doni te ruani te dhenat</b> e ceshtjes?");
//				
//			}
//		});
//		
//		
//		splitPanel.setFirstComponent(vl);
//		
//		splitPanel.setHeight("700px");
//		splitPanel.setMinSplitPosition(150, Unit.PIXELS);
//		splitPanel.setMaxSplitPosition(150, Unit.PIXELS);
//		
//		caseTree.setImmediate(true);
//		map.put(EntityTypeEnum.ER, this.erDataLayout);
//		map.put(EntityTypeEnum.PLACE, this.placeDataLayout);
//		map.put(EntityTypeEnum.PERSON, this.personDataLayout);
//		map.put(EntityTypeEnum.VEHICLE, this.vehicleDataLayout);
//		map.put(EntityTypeEnum.DRUG, this.drugDataLayout);
//		map.put(EntityTypeEnum.WEAPON, this.weaponDataLayout);
//		map.put(EntityTypeEnum.ITEM, this.itemDataLayout);
////		map.put(EntityTypeEnum.NUMBER, this.numberDataLayout);
//		map.put(EntityTypeEnum.ORGANIZATION, this.organizationDataLayout);
//		map.put(EntityTypeEnum.OFFICER, this.officerDataLayout);
//		map.put(EntityTypeEnum.DOCUMENT, this.docDataLayout);
//		
//		for (Iterator iterator = map.values().iterator(); iterator.hasNext();) {
//			AppEntityLayout appEntityLayout = (AppEntityLayout) iterator.next();
//			appEntityLayout.addAppEntityListener(this);
//			
//		}
//		
//		final LoadCaseWindow loadCaseWindow = new LoadCaseWindow(true);
//		loadCaseWindow.addListener(new ReturnObjectListener() {
//			
//			@Override
//			public <T> void returnObject(T result) {
//				if(result != null){
//					loadCase((Case) result);
//					loadCaseWindow.close();
//				}
//			}
//		});
//		
//		CaseManagementUI.getCurrent().addWindow(loadCaseWindow);
//		
//		caseTree.addValueChangeListener(new ValueChangeListener() {
//			
//			@Override
//			public void valueChange(ValueChangeEvent event) {
//				if(event.getProperty() != null){
//					if("ASSOCIATIONS".equals(event.getProperty().getValue())){
//						CaseLayout.this.splitPanel.setSecondComponent(assocDataLayout);
//					}
//					else{
//						if (event.getProperty().getValue() instanceof AppEntity){
//							loadAppEntity((AppEntity) event.getProperty().getValue());
//							
//						}
//					}
//					
//				}
//				
//			}
//		});
//		
//		
//		caseTree.addActionHandler(new Handler() {
//			
//			@Override
//			public void handleAction(Action action, Object sender, Object target) {
//
//				if(action == GeneralVars.ADD){
//					if(target.toString().equals(EntityTypeEnum.ER)){
//						if(pCase.getAppEntityByType(EntityTypeEnum.ER) != null){
//							HandleNotification.showWarningOnScreen("Ne ceshtje mund te shtohet vetem nje raport ngjarje");
//							return;
//						}
//					}
//					
//					else if(target.toString().equals(EntityTypeEnum.SR) && reportEntity != null){
//						
//						
//					}
//					CaseLayout.this.addAppEntity(EntityTypeEnum.valueOf(target.toString()));	
//					caseTree.select(target);
//				}
//				
//			}
//			
//			@Override
//			public Action[] getActions(Object target, Object sender) {
//				 if(target == null) return null;
//				 if(target == EntityTypeEnum.ER 
//						 || target == EntityTypeEnum.SR
//						 || target == EntityTypeEnum.PLACE
//						 || target == EntityTypeEnum.PERSON
//						 || target == EntityTypeEnum.VEHICLE
//						 || target == EntityTypeEnum.WEAPON
//						 || target == EntityTypeEnum.DRUG
////						 || target == EntityTypeEnum.NUMBER
//						 || target == EntityTypeEnum.ORGANIZATION
//						 || target == EntityTypeEnum.ITEM
//						 || target == EntityTypeEnum.OFFICER
//						 || target == EntityTypeEnum.DOCUMENT)
//	               return new Action[]{GeneralVars.ADD};
//				 return null;
//			}
//		});
//		
//		
//
//	}
//	
//	private void populateTree(){
//		if(pCase.getEntityList() == null) return;
//		List<Object> objs = new ArrayList<Object>(caseTree.getItemIds());
//		
//		for (Object obj : objs) {
//			if(obj instanceof AppEntity){
//				caseTree.removeItem(obj);
//			}
//		}
//		for (AppEntity appEntity : pCase.getEntityList()) {
//			this.addAppEntityToTree(appEntity);
//		}
//	}
//	
//	private void loadCase(Case _case){
//		this.pCase = _case;
//		this.populateTree();
//		this.assocDataLayout.loadCase(pCase);
//		this.caseDataLayout.setCase(pCase);
//		CaseLayout.this.splitPanel.setSecondComponent(caseDataLayout);
//	}
//	
//
//	
//	private void addAppEntity(EntityTypeEnum entityTypeEnum){
//		AppEntityLayout appEntityLayout = map.get(entityTypeEnum);
//		
//		if(caseTree.getChildren(entityTypeEnum) != null)
//			appEntityLayout.addAppEntity(caseTree.getChildren(entityTypeEnum).size());
//		else
//			appEntityLayout.addAppEntity(0);
//		CaseLayout.this.splitPanel.setSecondComponent(appEntityLayout);
//	}
//	
//	private void loadAppEntity(AppEntity appEntity){
//		AppEntityLayout appEntityLayout = map.get(appEntity.getEntityType());
//		
//		appEntityLayout.loadAppEntity(appEntity, appEntity.isNewRecord());
//		
//		
//			
//		CaseLayout.this.splitPanel.setSecondComponent(appEntityLayout);
//	}
//	
//
//	@Override
//	public void storeInMemory(AppEntity appEntity) {
//		if(appEntity != null){
//			appEntity.setPoliceCase(pCase);
//			pCase.addAppEntity(appEntity);
//			if(appEntity.getEntityType().equals(EntityTypeEnum.ER) || appEntity.getEntityType().equals(EntityTypeEnum.SR)) reportEntity = appEntity;
//			else{
//				if(reportEntity != null && reportEntity.getEntityType().equals(EntityTypeEnum.ER)) appEntity.setReportEntity(reportEntity);	
//			}
//			
//			
//			this.addAppEntityToTree(appEntity);
//		}
//		
//	}
//	
//	
//	private void addAppEntityToTree(AppEntity appEntity){
//		this.caseTree.addItem(appEntity);
//		
//		if(appEntity.getEntityType().equals(EntityTypeEnum.ER)){
//			if(this.pCase.getCaseId() == null) 
//				this.pCase.setCaseId(appEntity.getEventReport().getUniqueNumber().getUniqueNumber());
//
//			this.caseTree.setItemCaption("CASE", "Ceshtje nr. " + this.pCase.getCaseId());
//			
//			
//			this.caseTree.setItemCaption(appEntity, appEntity.getEventReport().getUniqueNumber().getUniqueNumber());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.ER);
//			this.caseTree.setItemCaption(EntityTypeEnum.ER, EntityTypeEnum.ER.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.ER).size() + ")");
//		}
//		else if(EntityTypeEnum.SR.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getSupplementReport().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.SR);
//			this.caseTree.setItemCaption(EntityTypeEnum.SR, EntityTypeEnum.SR.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.SR).size() + ")");
//		}
//		else if(EntityTypeEnum.PLACE.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getPlaces().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.PLACE);
//			this.caseTree.setItemCaption(EntityTypeEnum.PLACE, EntityTypeEnum.PLACE.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.PLACE).size() + ")");
//		}
//		else if(EntityTypeEnum.PERSON.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getPerson().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.PERSON);
//			this.caseTree.setItemCaption(EntityTypeEnum.PERSON, EntityTypeEnum.PERSON.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.PERSON).size() + ")");
//			
//		}
//		else if(EntityTypeEnum.VEHICLE.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getVehicle().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.VEHICLE);
//			this.caseTree.setItemCaption(EntityTypeEnum.VEHICLE, EntityTypeEnum.VEHICLE.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.VEHICLE).size() + ")");
//		}
//		else if(EntityTypeEnum.DRUG.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getDrugs().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.DRUG);
//			this.caseTree.setItemCaption(EntityTypeEnum.DRUG, EntityTypeEnum.DRUG.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.DRUG).size() + ")");
//		}
//		else if(EntityTypeEnum.WEAPON.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getWeapons().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.WEAPON);
//			this.caseTree.setItemCaption(EntityTypeEnum.WEAPON, EntityTypeEnum.WEAPON.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.WEAPON).size() + ")");
//		}
//		else if(EntityTypeEnum.ITEM.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getObjects().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.ITEM);
//			this.caseTree.setItemCaption(EntityTypeEnum.ITEM, EntityTypeEnum.ITEM.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.ITEM).size() + ")");
//		}
////		else if(EntityTypeEnum.NUMBER.equals(appEntity.getEntityType())){
////			this.caseTree.setItemCaption(appEntity, appEntity.getNumbers().toString());
////			this.caseTree.setParent(appEntity, EntityTypeEnum.NUMBER);
////			this.caseTree.setItemCaption(EntityTypeEnum.NUMBER, EntityTypeEnum.NUMBER.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.NUMBER).size() + ")");
////		}
//		else if(EntityTypeEnum.ORGANIZATION.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getOrganizations().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.ORGANIZATION);
//			this.caseTree.setItemCaption(EntityTypeEnum.ORGANIZATION, EntityTypeEnum.ORGANIZATION.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.ORGANIZATION).size() + ")");
//		}
//		else if(EntityTypeEnum.OFFICER.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getOfficers().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.OFFICER);
//			this.caseTree.setItemCaption(EntityTypeEnum.OFFICER, EntityTypeEnum.OFFICER.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.OFFICER).size() + ")");
//		}
//		else if(EntityTypeEnum.DOCUMENT.equals(appEntity.getEntityType())){
//			this.caseTree.setItemCaption(appEntity, appEntity.getDocument().toString());
//			this.caseTree.setParent(appEntity, EntityTypeEnum.DOCUMENT);
//			this.caseTree.setItemCaption(EntityTypeEnum.DOCUMENT, EntityTypeEnum.DOCUMENT.getCaption() + "(" + caseTree.getChildren(EntityTypeEnum.DOCUMENT).size() + ")");
//		}
//	}
//	
//	
//	private ConfirmDialogAction getConfirmDialogAction(){
//		ConfirmDialogAction confirm = new ConfirmDialogAction(){
//
//			@Override
//			public void actYes() {
//				Result<Case> result =CaseManagementUI.appStatelessBean.saveCase(pCase);
//				if(result.isSucceeded()){
//					HandleNotification.showInfoOnTray("Ceshtja u ruajt me sukses");
//					loadCase(result.getObject());
//				}
//					
//					
//				else
//					HandleNotification.showErrorOnScreen(result.getMessage());
//				
//			}
//
//			@Override
//			public void actNO() {
//				// TODO Auto-generated method stub
//				
//			}
//			
//		};
//		return confirm;
//	}
	
}
